<template>
	<view>
		<input id="input1" placeholder="请输入昵称"  v-model="nicheng" maxlength="12"/>
		<text>限2~12个中文、英文或数字</text>
		
	</view>
	
</template>

<script>
	
	export default{
		data(){
			return{
				nicheng:"",
			}
			
		},
		
		
		onShow() {
			
			this.nicheng=uni.getStorageSync("nicheng");
		},
		onNavigationBarButtonTap() {
			if(this.nicheng.length<2){
				uni.showToast({
					title:"至少两个字长",
					icon:"none"
				})
			}
			else{
				uni.request({
					url:getApp().globalData.http+"/user/modifynicheng",
					method:"POST",
					data:{
						"new_nicheng":this.nicheng
					},
					header:{
						'content-type':"application/x-www-form-urlencoded",
						"Authorization":uni.getStorageSync("token")
					},
					success: (res) => {
						if(res.data=="no_token"){
							uni.showToast({
								title:"请先登陆",
								icon:"none"
							})
						}
						else if(res.data=="fail"){
							uni.showToast({
								title:"请稍后重试", 
								icon:"none"
							})
						}
						else{
							uni.setStorageSync("nicheng",res.data);
							uni.navigateBack({
								delta:getCurrentPages().length-2
							})
						}
					}
				})
			}
			
			
		}
	}
	
</script>

<style scoped>
	view{
		height: 100%;
		background-color: #F4F4F4;
		overflow: hidden;
		display: flex;
		flex-direction: column;
	}
	text{
		font-size: 13px;
		margin-left: 10px;
		margin-top: 10px;
		color: #C0C0C0;
	}
	#input1{
		height: 50px;
		background-color: #FFFFFF;
		line-height: 15px;
		padding-left: 10px;
		margin-top: 10px; 
		
	}
	
	
</style>
